package com.surpassun.emall.repository;

import java.util.List;

import javax.persistence.Query;

import org.springframework.stereotype.Repository;

import com.surpassun.emall.model.Category;

@Repository
public class CategoryRepository extends AbstractRepository<Category> {
	
	private final String QUERY_GET_POPULAR_CATEGORIES = "Category_GetPopularCategories";
	private final String QUERY_GET_ROOT_CATEGORIES = "Category_GetRootCategories";

	public CategoryRepository() {
		super(Category.class);
	}

	@SuppressWarnings("unchecked")
	public List<Category> getPopularCategories(List<Long> referenceIds) {
		Query query = super.getEntityManager().createNamedQuery(QUERY_GET_POPULAR_CATEGORIES);
    	query.setParameter("referenceIds", referenceIds);
    	return (List<Category>)query.getResultList();
	}

	@SuppressWarnings("unchecked")
	public List<Category> getRootCategories() {
		Query query = super.getEntityManager().createNamedQuery(QUERY_GET_ROOT_CATEGORIES);
    	return (List<Category>)query.getResultList();
	}
}
